import os
import json

# 设置目标路径
directory_path = r"F:\Frames\tissue_bag\tissue_bag_label_zzy\val"

# 遍历目录下的所有JSON文件
for filename in os.listdir(directory_path):
    if filename.endswith(".json"):
        file_path = os.path.join(directory_path, filename)

        # 打开并加载JSON文件
        with open(file_path, 'r', encoding='utf-8') as file:
            data = json.load(file)

        # 遍历所有标签，修改"label"值为 "tissue_bag"
        for shape in data.get('shapes', []):
            shape['label'] = 'tissue_bag'

        # 保存修改后的数据
        with open(file_path, 'w', encoding='utf-8') as file:
            json.dump(data, file, indent=4, ensure_ascii=False)

print("所有JSON文件的label已修改为'tissue_bag'！")
